package controller;

import core.BaseServlet;
import service.FoodService;
import service.UploadService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "FoodServlet", urlPatterns = "/food")
public class FoodServlet extends BaseServlet {

    private FoodService foodService = new FoodService();

    /**
     * 菜品设置页面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void foodManagePage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/pages/foodManage/foodManage/foodManage.jsp").forward(request, response);
    }

    /**
     * 菜品设置页面菜品列表
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void foodList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foodService.foodList(request, response);
    }

    /**
     * 菜品设置页面 获取所有菜品类型
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void getAllFoodType(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foodService.getAllFoodType(request, response);
    }

    /**
     * 删除菜品
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void delete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foodService.delete(request, response);
    }

    /**
     * 真删
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void realDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foodService.realDelete(request, response);
    }

    /**
     * 恢复
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void restore(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foodService.restore(request, response);
    }

    /**
     * 删除菜品
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void addPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/pages/foodManage/foodManage/foodAdd.jsp").forward(request, response);
    }

    /**
     * 删除菜品
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void upload(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        UploadService uploadService = new UploadService();
        uploadService.upload(request, response);
    }

    /**
     * 跳转至回收站的方法
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void foodManageDeletedPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/pages/foodManage/foodManage/foodManageDeleted.jsp").forward(request, response);
    }

    /**
     * 添加菜品
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void add(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foodService.add(request, response);
    }

    /**
     * 编辑菜品
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void edit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foodService.edit(request, response);
    }

    /**
     * 编辑菜品页面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void editFoodPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foodService.editFoodPage(request, response);
    }

    /**
     * 菜品图片页面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void foodImgPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foodService.foodImgPage(request, response);
    }

    /**
     * 菜品类型管理页面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void foodTypeManagePage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/pages/foodManage/foodTypeManage/foodTypeManage.jsp").forward(request, response);
    }


    /**
     * 添加菜品类型
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void addType(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foodService.addType(request, response);
    }

    /**
     * 添加菜品类型页面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void addTypePage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/pages/foodManage/foodTypeManage/foodTypeAdd.jsp").forward(request, response);
    }

    /**
     * 设置菜品类型
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void editFoodType(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foodService.editFoodType(request, response);
    }

    /**
     * 删除菜品类型
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void deleteFoodType(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        foodService.deleteFoodType(request, response);
    }

}
